<template>
  <!--公告-->
  <div class="announcement">
    <!--统一样式-->
    <div class="announcement_title">
      <div class="announcement_title_icon">
        <img src="./../../../assets/home/gonggao.svg" alt="" />
      </div>
      <p class="announcement_title_font">公告</p>
      <div class="announcement_title_more" @click="handelLink">
        更多 <i class="el-icon-d-arrow-right"></i>
      </div>
    </div>
    <!--内容-->
    <div class="announcement_content">
      <div
        class="announcement_content_table"
        v-for="item in annDataList"
        :key="item.id"
        @click="handelDetail(item)"
      >
        <p class="announcement_content_table_left">{{ item.title }}</p>
        <p class="announcement_content_table_right">{{ item.createdAt }}</p>
      </div>
    </div>
  </div>
</template>

<script>
import { getAnnouncementList } from "@/api/home";
export default {
  name: "announcement",
  data() {
    return {
      annData: {
        page: 1,
        size: 7,
      },
      annDataList: [],
    };
  },
  mounted() {
    this.getAnnouncementList();
  },
  methods: {
    getAnnouncementList() {
      getAnnouncementList(this.annData).then((response) => {
        if (response.data.code === 20000) {
          const { list } = response.data.results;
          this.annDataList = list ? list : [];
        }
      });
    },
    // 跳转到list页面
    handelLink() {
      this.$router.push({
        path: "/announcement/announcementList",
        query: {
          routerName: "公告列表",
        },
      });
    },
    // 直接到详情
    handelDetail(item) {
      if (item.url) {
        let path = window.location.protocol + "//" + item.url;
        window.open(path, "_blank");
      } else {
        this.$router.push({
          path: "/announcement/announcementDetails",
          query: {
            routerName: "公告列表",
            annId: item.id,
          },
        });
      }
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.announcement {
  width: 622px;
  height: 542px;
  color: #333;
  .announcement_title {
    margin-top: 40px;
    display: flex;
    padding-bottom: 15px;
    border-bottom: 2px solid #0a7b19;
    .announcement_title_icon {
      width: 32px;
      height: 32px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .announcement_title_font {
      font-weight: bold;
      font-size: 24px;
      margin-left: 15px;
      width: 100px;
    }
    .announcement_title_more {
      font-size: 12px;
      height: 32px;
      line-height: 32px;
      text-align: right;
      width: 475px;
      cursor: pointer;
    }
  }
  .announcement_content {
    margin-top: 24px;
    .announcement_content_table {
      font-size: 18px;
      height: 56px;
      line-height: 56px;
      border-bottom: 1px dashed #dadada;
      display: flex;
      justify-content: space-between;
      cursor: pointer;
      transition: all 0.2s linear;
      &:hover {
        background-color: #e3e3e3;
      }
      .announcement_content_table_left {
        font-weight: bold;
        overflow: hidden; //溢出隐藏
        white-space: nowrap; //禁止换行
        text-overflow: ellipsis;
      }
      .announcement_content_table_right {
        font-size: 14px;
        color: #808080;
      }
    }
  }
}
</style>
